import request from '@/utils/request'

export default {
  // 获取员工列表
  getEmployeeList(params) {
    return request({
      url: '/employee/list',
      method: 'get',
      params
    })
  },
  // 导出员工数据的接口
  exportEmployee() {
    return request({
      url: '/employee/export',
      responseType: 'blob',//接收一个blob二进制流的文件
      method: 'get',
    })
  },

  // 获取下载员工数据的模板
  downloadTemplate() {
    return request({
      url: '/employee/template',
      responseType: 'blob',//接收一个blob二进制流的文件
      method: 'get',
    })
  },

  // 上传员工数据
  uploadEmployeeExcel(formData) {
    return request({
      url: '/employee/uploadEmployeeExcel',
      headers: {
        'Content-Type': 'multipart/form-data'
      },
      method: 'post',
      data: formData
    })
  },
  // 删除员工
  deleteEmployee(userId) {
    return request({
      url: `/employee/${userId}`,
      method: 'delete'
    })
  },
  // 获取员工详情
  getEmployeeDetail(userId) {
    return request({
      url: `/employee/getEmployeeDetail/${userId}`,
      method: 'get'
    })
  },
  // 新增员工
  addEmployee(data) {
    return request({
      url: '/employee/addEmployee',
      method: 'post',
      data
    })
  },
  // 更新员工
  updateEmployee(data) {
    return request({
      url: '/employee/updateEmployee',
      method: 'put',
      data
    })
  },

  // 上传员工头像
  uploadEmployeeAvatar(formData) {
    return request({
      url: '/file/upload',
      headers: {
        'Content-Type': 'multipart/form-data'
      },
      method: 'post',
      data: formData
    })
  },

  // 分配员工角色
  assignRoles(emplId, roleIds) {
    return request({
      url: `/employee/assignRoles/${emplId}`,
      method: 'put',
      params: {
        roleIds:roleIds.join(',')
      }
    })

  }

}